package cn.leftsite.juc.pattern.nio;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * @author wangjinqiang
 * @date 2019-06-06
 */
public class EchoClient {
    public static void main(String[] args) {

        try (
                Socket client = new Socket("127.0.0.1", 8000);
                PrintWriter writer = new PrintWriter(client.getOutputStream(), true);
                BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream()));
        ) {
            writer.println("Hello!");

            System.out.println("from server: " + reader.readLine());

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
